package com.br.unisal.library.business;

import com.br.unisal.library.controller.LendingOperationResult;
import com.br.unisal.library.exception.NullValueException;
import com.br.unisal.library.operations.settings.OperationSettings;


public class BookLender {
	
	OperationSettings operation;

	public BookLender(OperationSettings operation) {
		this.operation = operation;
	}

	public LendingOperationResult lend() throws IllegalArgumentException, NullValueException {
		LendingOperationResult result = null;
		Book book = searchBook();
		if(book != null) {
			book = lend(book);
			result = new LendingOperationResult(true);
			result.setResultedBook(book);  
		} else {
			result = new LendingOperationResult(false);
		}
		return result;	
	}

	private Book lend(Book book) throws IllegalArgumentException, NullValueException {
		Lending lending = null;
		if(book.isAvailable()) {
			lending = new Lending(book);
			book.setLending(lending);
		}	
		return book;
	}

	private Book searchBook() throws IllegalArgumentException, NullValueException {
		LibraryBooks books = new LibraryBooks();
		Book book =  null;
		/*Criteria criterion = operation.getCriterio();
		String parameter = operation.getParametro();
		books.getBook(criterion, parameter);*/
		return book;
	}

}
